import type { AddClassFormData } from './types';
import { request } from '@/utils';

// 定义我的班级 0 全部 1 我管理的 2 我加入的
export const getClassList = (type: number) => {
  return request.get(`api/myclass_tea?type=${type}`);
};

// 获取班级信息
export const getClassInfo = (id: number) => {
  return request.get(`api/myclass/ClassInformation?class_id=${id}`);
};

// 添加班级
export const addClass = (data: AddClassFormData) => {
  return request.post('api/myclass/addClass', data);
};

// 一键删除
export const deleteClass = (ids: number[]) => {
  return request.delete('api/myclass_tea', { data: { ids } });
};

// 添加学生
export const addClassStudent = (data: any) => {
  return request.post('api/myclass/addStudent', data);
};

// 修改班级信息
export const updateClassInfo = (data: any, class_id: number) => {
  return request.post(`api/myclass/ClassInformation?class_id=${class_id}`, data);
};

// 获取班级学生列表
export const getClassStudentList = (class_id: number) => {
  return request.get(`api/myclass/class_stu_info?class_id=${class_id}`);
};

// 搜索学生
export const searchStudent = (class_id: number, studentName: string) => {
  return request.get(`/api/myclass/search?class_id=${class_id}&studentName=${studentName}`);
};

// 批量删除学生
export const deleteStudent = (class_id: number, ids: number[]) => {
  return request.delete(`/api/myclass/del_student?class_id=${class_id}`, { data: { ids } });
};

// 学生详情
export const getStudentDetail = (student_id: number) => {
  return request.get(`/api/myclass/stu_detail?student_id=${student_id}`);
};

// 获取学生加入的班级
export const getStudentJoinClass = () => {
  return request.get('/api/myclass/myclass_stu');
};

// 邀请码加入班级
export const joinClassByCode = (ic: string) => {
  return request.post('/api/myclass/ic_join', { ic });
};

/** 获取班级知识库 */
export const getClassKb = (page: number, page_size: number, class_id: number) => {
  return request.post('/api/knowledgeBases/GetClassKB', { page, page_size, class_id  });
};

/** 批量导入学生 */
export const batchImportStudent = (formDataParams: { class_id: number, file: File }) => {
  const formData = new FormData();
  formData.append('class_id', formDataParams.class_id.toString()); // 关键修复
  formData.append('file', formDataParams.file);
  return request.post('/api/myclass/AddStu_excel', formData);
};